﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using yzrilyzr.util;

namespace FAQ_UI
{
	public sealed class MouseEvent
	{
		int leftState;
		public event LeftDown leftDown;
		public event LeftUp leftUp;
		public event LeftStartDrag leftStartDrag;
		public event LeftDrag leftDrag;
		public event LeftDragDrop leftDragDrop;
		public event LeftClick leftClick;
		public event Move move;
		public MouseEvent(UIElement element)
		{
			element.MouseLeftButtonDown += mouseLeftDown;
			element.MouseLeftButtonUp += mouseLeftUp;
			element.MouseMove += mouseMove;
		}

		private void mouseLeftDown(object sender, MouseButtonEventArgs e)
		{
			leftState = 1;
			leftDown?.Invoke(sender,e);
		}

		private void mouseLeftUp(object sender, MouseButtonEventArgs e)
		{
			if (leftState == 1)
			{
				leftClick?.Invoke(sender, e);
			}
			if (leftState == 2)
			{
				leftDragDrop?.Invoke(sender, e);
			}
			leftState = 0;
			leftUp?.Invoke(sender,e);
		}

		private void mouseMove(object sender, MouseEventArgs e)
		{
			move?.Invoke(sender, e);
			if (leftState == 1)
			{
				leftState = 2;
				leftStartDrag?.Invoke(sender, e);
			}
			else if (leftState == 2)
			{
				leftDrag?.Invoke(sender, e);
			}
		}
		public delegate void LeftDown(object sender, MouseButtonEventArgs e);
		public delegate void LeftUp(object sender, MouseButtonEventArgs e);
		public delegate void LeftStartDrag(object sender, MouseEventArgs e);
		public delegate void LeftDrag(object sender, MouseEventArgs e);
		public delegate void LeftDragDrop(object sender, MouseButtonEventArgs e);
		public delegate void Move(object sender, MouseEventArgs e);
		public delegate void LeftClick(object sender, MouseButtonEventArgs e);
	}
}
